package com.lzj.demo.design.singleton;

/**
 * 双重锁校验
 * */
public class DoubleCheckSingleton {
    //第一次加锁
    private volatile static DoubleCheckSingleton instance;
    //构造私有化
    private DoubleCheckSingleton() {}
    //提供一个访问它的全局访问点
    public static DoubleCheckSingleton getInstance(){
        if (instance == null) {
            //第二次加锁
            synchronized (DoubleCheckSingleton.class) {
                if (instance == null) {
                    instance = new DoubleCheckSingleton();
                }
            }
        }
        return instance;
    }
}
